package com.wzdigit.wms.raw.controller.asn.report;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.raw.client.request.asn.report.asnreceive.AsnReceiveExportRequest;
import com.wzdigit.wms.raw.client.request.asn.report.asnreceive.AsnReceiveSearchRequest;
import com.wzdigit.wms.raw.client.response.asn.receive.AsnReceieveEnums;
import com.wzdigit.wms.raw.client.response.asn.report.asnreceive.AsnReceiveDtlRespone;
import com.wzdigit.wms.raw.client.response.asn.report.asnreceive.AsnReceiveGoodsRespone;
import com.wzdigit.wms.raw.client.response.asn.report.asnreceive.AsnReceiveHeaderRespone;
import com.wzdigit.wms.raw.client.response.asn.report.ortherasn.OrtherAsnEnums;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.asn.report.AsnReceiveReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 送货单控制层
 * Created by zyf on 2021/7/16 18:42
 */
@RestController
@Api(tags = "送货单")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class AsnReceiveReportController {
    private final String REQUEST_MODEL = "/receiveReport";

    @Autowired
    private AsnReceiveReportService reportService;

    @ApiOperation(value = "获取交货单主页（分页）", notes = "获取交货单主页（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Header", method = RequestMethod.GET)
    public PagerInfo<List<AsnReceiveHeaderRespone>> searchAsnReceiveHeader(
            AsnReceiveSearchRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return reportService.searchHeader(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "获取交货单明细（分页）", notes = "获取交货单明细（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Dtl", method = RequestMethod.GET)
    public PagerInfo<List<AsnReceiveDtlRespone>> searchAsnReceiveDtl(
            BigDecimal asnHeaderId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return reportService.searchDtl(asnHeaderId,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "获取交货单序列（分页）", notes = "获取交货单序列（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Goods", method = RequestMethod.GET)
    public PagerInfo<List<AsnReceiveGoodsRespone>> searchAsnReceiveGood(
            BigDecimal asnHeaderId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return reportService.searchGoods(asnHeaderId,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出交货单", notes = "导出交货单")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportSaleInv", method = RequestMethod.POST)
    public void exportOrtherAsnReport(
            @RequestBody AsnReceiveExportRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            reportService.exportAsnTrsnReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "取消交货单", notes = "取消交货单")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportReceivceReport", method = RequestMethod.POST)
    public Result<?> removeAsn(
            @RequestBody List<BigDecimal> asnHeaderIds,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return  reportService.removeAsn(asnHeaderIds,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "单据类型下拉框", notes = "单据类型下拉框")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/getReceiveEnums", method = RequestMethod.GET)
    public List<OrtherAsnEnums> getTypeEnums(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.getAsnReceiveEnumsList();
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "订单状态下拉框", notes = "订单状态下拉框")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/getReceive/Status/Enums", method = RequestMethod.GET)
    public List<AsnReceieveEnums> getStatusEnums(
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reportService.getAsnReceiveStatusEnum();
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }




}
